package com.example.teamilkmall.controller;

import com.example.teamilkmall.controller.vo.ResultVO;
import com.example.teamilkmall.entity.OrdersInfo;
import com.example.teamilkmall.service.OrdersInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ordersInfo")
public class OrdersInfoController extends BaseController{
    private final OrdersInfoService ordersInfoService;

    public OrdersInfoController(OrdersInfoService ordersInfoService) {
        this.ordersInfoService = ordersInfoService;
    }
    @GetMapping("/listOrdersInfo")
    public ResultVO<PageInfo<OrdersInfo>> listOrders(Integer limit, Integer page, Integer id){
        PageInfo<OrdersInfo> pageInfo = ordersInfoService.listOrdersInfo(limit, page, id);
        return success(pageInfo);
    }

    @PostMapping("/updateOrdersInfo")
    public ResultVO updateOrders(OrdersInfo orders){
        ordersInfoService.updateOrdersInfo(orders);
        return success();
    }

    @PostMapping("/deloneOrdersInfo")
    public ResultVO deloneOrders(Integer id){
        ordersInfoService.deloneOrdersInfo(id);
        return success();
    }

    @PostMapping("/addOrdersInfo")
    public ResultVO addOrders(OrdersInfo orders){
        ordersInfoService.addOrdersInfo(orders);
        return success();
    }

    @PostMapping("/listOrdersInfoAll")
    public ResultVO<List<OrdersInfo>> getOrdersList(){
        return success(ordersInfoService.listOrdersinfo());
    }
}
